package com.bookstore.spring.service;


import com.bookstore.spring.dao.BookMap;
import com.bookstore.spring.pojo.Book;
import com.bookstore.spring.pojo.ShoppingCart;
import com.bookstore.spring.web.CriteriaBook;
import com.bookstore.spring.web.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Created by Admin on 2016/8/12.
 */

@Service("bookService")
public class BookServiceImp implements BookService {
    @Autowired
    private BookMap bookMap;

    public BookMap getBookMap() {
        return bookMap;
    }

    public void setBookMap(BookMap bookMap) {
        this.bookMap = bookMap;
    }

    public Page<Book> getPage(CriteriaBook cb) {
        return bookMap.getPage(cb);
    }

    public Book getBook(int id) {
        return bookMap.getBook(id);
    }

    /**
     * 根据商品的id 和购物车
     *
     * @param id
     * @param sc
     */
    public boolean addToCart(int id, ShoppingCart sc) {
        Book book = bookMap.getBook(id);
        if (book != null) {
            sc.addBook(book);
            return true;
        }
        return false;
    }

    public long getCountWithName(String title) {
        long count = bookMap.getCountWithTitle(title);
        return count;
    }
}
